package priv.menguer.servicelocator.controller;

import priv.menguer.servicelocator.service.Service;

/**
 * @Title ServiceLocator.java
 * @description TODO
 * @time 2018年10月26日 下午2:47:40
 * @author menguer@126.com
 * @version 1.0
 */
public class ServiceLocator {
	private static Cache cache;

	static {
		cache = new Cache();
	}

	public static Service getService(String jndiName) {

		Service service = cache.getService(jndiName);

		if (service != null) {
			return service;
		}

		InitialContext context = new InitialContext();
		Service service1 = (Service) context.lookup(jndiName);
		cache.addService(service1);
		return service1;
	}
}
